/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.server.db.tasks;

import pl.cezary.butler.walili.server.ServerTask;
import pl.cezary.butler.walili.server.db.Queries;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Date;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import pl.cezary.butler.walili.server.db.tables.ZadReszta;

/**
 *
 * @author Przemysław Bałdyga
 */
public class GetTasksByDateTask extends FetchingTask<List<ServerTask>> {

    final static String QUERY_STRING = Queries.SELECT_ZADANIE_BY_DATE.getQuery();
    private final Date DATA_1;
    private final Date DATA_2;
    private List<ServerTask> wynik;

    public GetTasksByDateTask(java.util.Date data_1, java.util.Date data_2) {
        DATA_1 = convert(data_1);
        DATA_2 = convert(data_2);
    }

    @Override
    public void executeInternal() {                        
        wynik = getJdbcTemplate().query(QUERY_STRING, TaskRowMapper.getInstance(), DATA_1,DATA_2);        
    }

    @Override
    protected List<ServerTask> $getResultsNonLocking() {
        return wynik;
    }

    private static Date convert(java.util.Date d) {
        return new Date(d.getTime());
    }
}
